home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MISC.SWG / 0031_File at end of EXE.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  3KB  |  127 lines

  1. {
  2. JACK MOFFITT
  3.  
  4. >Okay, how about this: If I wanted to attach it to the back of an EXE, I
  5. >COPY /B it. Now, in the source code, how do I find the picture and set
  6. >everything up? I mean do you LoadGif (Ofs,Seg) or something? That's what
  7. >I mean, and I'm sorry to put you through this.
  8.  
  9. Ok..  here we go..  everyone seems to be asking this, so i'll just post
  10. some source.  Granted this is not a COMPLETE program, just an example on
  11. how to read the header, and get a pointer to the GIF.
  12. }
  13.  
  14. (* This code originally by Scott Johnson, I revised it later *)
  15.  
  16. function GetSize(N : byte) : word;
  17. function GetData(N : byte) : pointer;
  18. function GetDataCount : byte;
  19.  
  20. implementation
  21.  
  22. uses
  23.   Dos;
  24.  
  25. type
  26.   DataRec = record
  27.     Size : word;
  28.     Loc  : longint;
  29.   end;
  30.   DataArray    = array [1..255] of DataRec;
  31.   DataArrayPtr = ^DataArray;
  32.  
  33.   ExeDataRec = record
  34.     ActSize : word;
  35.   end;
  36.  
  37.  
  38. var
  39.   ExeFile   : file;
  40.   DataCount : byte;         { count of data records }
  41.   Data      : DataArrayPtr;
  42.  
  43. procedure OpenExe;
  44. begin
  45.   assign(ExeFile, ParamStr(0));
  46.   reset(ExeFile, 1);
  47. end;
  48.  
  49. procedure CloseExe;
  50. begin
  51.   Close(ExeFile);
  52. end;
  53.  
  54. procedure InitExe;
  55. var
  56.   ExeHdr : record
  57.     M, Z  : char;
  58.     Len   : word;
  59.     Pages : word;
  60.   end;
  61.   ExeLoc  : longint;
  62.   I       : byte;
  63.   ExeData : ExeDataRec;
  64. begin
  65.   OpenExe;
  66.   BlockRead(ExeFile, ExeHdr, SizeOf(ExeHdr));
  67.   if ExeHdr.Len = 0 then
  68.     ExeHdr.Len := $200;
  69.   ExeLoc := (longint(ExeHdr.Pages) - 1) shl 9 + longint(ExeHdr.Len);
  70.   Seek(ExeFile, ExeLoc);
  71.   BlockRead(ExeFile, DataCount, 1);      { read data count byte }
  72.   Inc(ExeLoc);
  73.   GetMem(Data, SizeOf(DataRec) * DataCount);
  74.   for I := 1 to DataCount do
  75.   begin
  76.     Seek(ExeFile, ExeLoc);
  77.     BlockRead(ExeFile, ExeData, SizeOf(ExeData));
  78.     Data^[I].Loc  := ExeLoc;
  79.     Data^[I].Size := ExeData.ActSize;
  80.     Inc(ExeLoc, ExeData.ActSize + 2);
  81.   end;
  82.   CloseExe;
  83. end;
  84.  
  85. function GetSize(N : byte) : word;
  86. begin
  87.   if N > DataCount then
  88.     RunError(201);
  89.   GetSize := Data^[N].Size;
  90. end;
  91.  
  92. function GetData(N : byte) : pointer;
  93. var
  94.   P, D    : pointer;
  95.   DataLoc : longint;
  96.   E       : ExeDataRec;
  97. begin
  98.   if N > DataCount then
  99.     RunError(201);
  100.   GetMem(P, Data^[N].Size);
  101.   OpenExe;
  102.   Seek(ExeFile, Data^[N].Loc + 2);   { +2 is to get past info record }
  103.   BlockRead(ExeFile, P^, Data^[N].Size);
  104.   CloseExe;
  105.   GetData := P;
  106. end;
  107.  
  108. function GetDataCount : byte;
  109. begin
  110.   GetDataCount := DataCount;
  111. end;
  112.  
  113. begin
  114.   InitExe;
  115. end.
  116.  
  117. {
  118. Ok.. that's it.  Call GetData(x) to get the location of the first
  119. element.  Datacount is the number of GIFs or whatever you have in there
  120. and the first two bytes are the actual size..  So to add a file, just
  121. make a temp file called ADDED.DAT, write a byte value for the datacount,
  122. and a word value for the filesize of the data you're adding, and then
  123. the data.  Hope this help all of you who wanted to be able to add ANSis,
  124. GIFs, and whatnot onto exes.  Also, with little modification, you can
  125. make it read from .DAT files with multiple gifs and stuff in them.
  126. }
  127.